<template>
  <div class="container">
    <div
      :class="[
        'box',
        { slopingRight: isMove == 'right' },
        { slopingLeft: isMove == 'left' },
      ]"
    >
      <div
        :class="[
          'left',
          { initSty: !isMove },
          { active: isMove && isActive == 'left' },
        ]"
        @click="btnClick('left')"
      >
        Recent
      </div>
      <div
        :class="['right', { active: isActive == 'right' }]"
        @click="btnClick('right')"
      >
        Archived
      </div>
      <div
        :class="[
          'slider',
          { leftMove: isMove == 'right' },
          { rightMove: isMove == 'left' },
        ]"
      ></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isActive: "left",
      isMove: "",
    };
  },
  methods: {
    btnClick(val) {
      this.isMove = val;
      this.isActive = val;
      // setTimeout(() => {
      //   this.isActive = val;
      // }, 1000);
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  margin: auto;
  width: 1200px;
  height: 400px;
  background-color: #f1f1f1;
  padding-top: 100px;
  perspective: 400px;
  transition: all 1s;
}
.box {
  position: relative;
  display: flex;
  margin: 0 auto;
  width: 400px;
  height: 100px;
  border-radius: 10px;
  background-color: #eeebee;
  box-shadow: -6px -6px 10px 4px rgba(255, 255, 255, 0.9),
    6px 6px 11px 4px rgba(170, 170, 170, 0.8);
  transform-style: preserve-3d;
  transition: all 1s;

  .left,
  .right {
    width: 200px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    font-size: 24px;
    color: #aaa;
    cursor: pointer;
  }
  .initSty {
    color: #333;
  }
  .active {
    // color: #333;
    animation: fontScale 1s ease-in forwards;
  }
  .slider {
    position: absolute;
    top: 10px;
    left: 20px;
    width: 160px;
    height: 80px;
    border-radius: 20px;
    background-color: transparent;
    box-shadow: inset 5px 5px 6px 4px rgba(204, 204, 204, 0.8),
      inset -5px -6px 11px 4px rgba(255, 255, 255, 0.8);
  }
  .leftMove {
    animation: leftMove 1s ease-in-out forwards;
  }
  .rightMove {
    animation: rightMove 1s ease-in-out forwards;
  }
}
.slopingLeft {
  transform-style: preserve-3d;
  animation: slopingLeft 1s linear forwards;
}
.slopingRight {
  transform-style: preserve-3d;
  animation: slopingRight 1s linear forwards;
}
@keyframes leftMove {
  from {
    transform: translateX(0px);
  }
  to {
    transform: translateX(200px);
  }
}
@keyframes rightMove {
  from {
    transform: translateX(200px);
  }
  to {
    transform: translateX(0px);
  }
}
@keyframes slopingRight {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(5deg);
  }
  100% {
    transform: rotateY(0deg);
  }
}
@keyframes slopingLeft {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(-5deg);
  }
  100% {
    transform: rotateY(0deg);
  }
}
@keyframes fontScale {
  from {
    transform: scale(1);
    color: #aaa;
  }
  to {
    transform: scale(1.1);
    color: #333;
  }
}
</style>